package javolution.text;

import javolution.util.FastComparator;

/* loaded from: classes2.dex */
public final class CharArray implements CharSequence, Comparable {
    private char[] _array;
    private String _asString;
    private int _length;
    private int _offset;

    public CharArray() {
    }

    public CharArray(CharSequence charSequence) {
        this._length = charSequence.length();
        this._array = new char[this._length];
        for (int i = 0; i < this._length; i++) {
            this._array[i] = charSequence.charAt(i);
        }
    }

    public CharArray(String str) {
        this._array = str.toCharArray();
        this._length = str.length();
        this._asString = str;
    }

    private boolean equals(CharSequence charSequence) {
        if (charSequence != null && this._length == charSequence.length()) {
            int i = this._length;
            int i2 = this._offset + i;
            do {
                i--;
                if (i < 0) {
                    return true;
                }
                i2--;
            } while (this._array[i2] == charSequence.charAt(i));
            return false;
        }
        return false;
    }

    public char[] array() {
        return this._array;
    }

    @Override // java.lang.CharSequence
    public char charAt(int i) {
        if (i < 0 || i >= this._length) {
            throw new IndexOutOfBoundsException("index: " + i);
        }
        return this._array[this._offset + i];
    }

    @Override // java.lang.Comparable
    public int compareTo(Object obj) {
        return FastComparator.LEXICAL.compare(this, obj);
    }

    public boolean equals(Object obj) {
        if (obj instanceof String) {
            return equals((String) obj);
        }
        if (obj instanceof CharArray) {
            return equals((CharArray) obj);
        }
        if (obj instanceof CharSequence) {
            return equals((CharSequence) obj);
        }
        return false;
    }

    public boolean equals(String str) {
        String str2 = this._asString;
        if (str2 != null) {
            if (str2 == str) {
                return true;
            }
            if (str2.equals(str)) {
                this._asString = str;
                if (str == str) {
                    return true;
                }
            }
            return false;
        } else if (str != null && this._length == str.length()) {
            int i = this._length;
            int i2 = this._offset + i;
            do {
                i--;
                if (i < 0) {
                    this._asString = str;
                    return true;
                }
                i2--;
            } while (this._array[i2] == str.charAt(i));
            return false;
        } else {
            return false;
        }
    }

    public boolean equals(CharArray charArray) {
        int i;
        if (this == charArray) {
            return true;
        }
        if (charArray != null && (i = this._length) == charArray._length) {
            char[] cArr = charArray._array;
            int i2 = charArray._offset + i;
            int i3 = this._offset + i;
            do {
                i3--;
                if (i3 < this._offset) {
                    return true;
                }
                i2--;
            } while (this._array[i3] == cArr[i2]);
            return false;
        }
        return false;
    }

    public int hashCode() {
        String str = this._asString;
        if (str != null) {
            return str.hashCode();
        }
        int i = 0;
        int i2 = this._offset;
        int i3 = 0;
        while (i < this._length) {
            i3 = (i3 * 31) + this._array[i2];
            i++;
            i2++;
        }
        return i3;
    }

    @Override // java.lang.CharSequence
    public int length() {
        return this._length;
    }

    public int offset() {
        return this._offset;
    }

    public final int offsetOf(char c) {
        int i = this._offset;
        int i2 = this._length + i;
        while (i < i2) {
            if (this._array[i] == c) {
                return i;
            }
            i++;
        }
        return -1;
    }

    public final int offsetOf(CharSequence charSequence) {
        boolean z;
        char charAt = charSequence.charAt(0);
        int length = charSequence.length();
        int i = this._offset;
        int i2 = ((this._length + i) - length) + 1;
        while (i < i2) {
            if (this._array[i] == charAt) {
                int i3 = 1;
                while (true) {
                    if (i3 >= length) {
                        z = true;
                        break;
                    } else if (this._array[i + i3] != charSequence.charAt(i3)) {
                        z = false;
                        break;
                    } else {
                        i3++;
                    }
                }
                if (z) {
                    return i;
                }
            }
            i++;
        }
        return -1;
    }

    public CharArray setArray(char[] cArr, int i, int i2) {
        this._array = cArr;
        this._offset = i;
        this._length = i2;
        this._asString = null;
        return this;
    }

    @Override // java.lang.CharSequence
    public CharSequence subSequence(int i, int i2) {
        if (i < 0 || i2 < 0 || i > i2 || i2 > length()) {
            throw new IndexOutOfBoundsException();
        }
        CharArray charArray = new CharArray();
        charArray._array = this._array;
        charArray._offset = this._offset + i;
        charArray._length = i2 - i;
        return charArray;
    }

    public boolean toBoolean() {
        int i = this._offset;
        if (this._length == 4) {
            char[] cArr = this._array;
            if (cArr[i] == 't' || cArr[i] == 'T') {
                char[] cArr2 = this._array;
                i++;
                if (cArr2[i] == 'r' || cArr2[i] == 'R') {
                    char[] cArr3 = this._array;
                    i++;
                    if (cArr3[i] == 'u' || cArr3[i] == 'U') {
                        char[] cArr4 = this._array;
                        i++;
                        if (cArr4[i] == 'e' || cArr4[i] == 'E') {
                            return true;
                        }
                    }
                }
            }
        }
        if (this._length == 5) {
            char[] cArr5 = this._array;
            if (cArr5[i] == 'f' || cArr5[i] == 'F') {
                char[] cArr6 = this._array;
                int i2 = i + 1;
                if (cArr6[i2] == 'a' || cArr6[i2] == 'A') {
                    char[] cArr7 = this._array;
                    int i3 = i2 + 1;
                    if (cArr7[i3] == 'l' || cArr7[i3] == 'L') {
                        char[] cArr8 = this._array;
                        int i4 = i3 + 1;
                        if (cArr8[i4] == 's' || cArr8[i4] == 'S') {
                            char[] cArr9 = this._array;
                            int i5 = i4 + 1;
                            if (cArr9[i5] == 'e' || cArr9[i5] == 'E') {
                                return false;
                            }
                        }
                    }
                }
            }
        }
        throw new IllegalArgumentException("Cannot parse " + ((Object) this) + " as boolean");
    }

    public double toDouble() {
        return TypeFormat.parseDouble(this);
    }

    public float toFloat() {
        return TypeFormat.parseFloat(this);
    }

    public int toInt() {
        return TypeFormat.parseInt(this);
    }

    public int toInt(int i) {
        return TypeFormat.parseInt(this, i);
    }

    public long toLong() {
        return TypeFormat.parseLong(this);
    }

    public long toLong(int i) {
        return TypeFormat.parseLong(this, i);
    }

    @Override // java.lang.CharSequence
    public String toString() {
        if (this._asString == null) {
            this._asString = new String(this._array, this._offset, this._length);
        }
        return this._asString;
    }
}
